package com.atung.merchant.controller;

import com.atung.merchant.result.ApiResult;
import com.atung.merchant.service.RoomService;
import com.atung.merchant.vo.IdRequest;
import com.atung.merchant.vo.RoomInfoEntity;
import com.atung.merchant.vo.query.QueryRoomInfoRequest;
import com.atung.merchant.vo.save.SaveRoomRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("/api/room")
@Api(tags = "房间管理")
public class RoomController {

    @Resource
    private RoomService roomService;

    @PostMapping("/save")
    @ApiOperation("新增房间")
    @PreAuthorize("hasRole('MASTER')")
    public ApiResult saveRoomInfo(@RequestBody SaveRoomRequest saveRoomRequest) {
        return roomService.saveRoomInfoService(saveRoomRequest);
    }

    @PostMapping("/delete")
    @ApiOperation("删除房间")
    @PreAuthorize("hasRole('MASTER')")
    public ApiResult deleteRoomInfo(@RequestBody IdRequest idRequest) {
        return roomService.deleteRoomInfoService(idRequest);
    }

    @PostMapping("/list")
    @ApiOperation("获取房间列表")
    public ApiResult getRoomList(@RequestBody QueryRoomInfoRequest queryRoomInfoRequest) {
        List<RoomInfoEntity> roomList=roomService.getRoomListService(queryRoomInfoRequest);
        return ApiResult.ok(roomList);
    }
}
